<template>
  <div class="quote-process">
    <el-select
      v-model="value"
      size="small"
      placeholder="引用流程设置"
      filterable
      popper-class="width240"
      @change="handleChange">
      <el-option
        v-for="(item, index) in processList"
        :key="index"
        :label="item.name"
        :title="item.name"
        :value="item.id" />
    </el-select>
  </div>
</template>

<script>
import ElMessage from '@/utils/message';
// api
import { processManagementDetail } from '@/api/legal';

export default {
  props: {
    processList: { // 流程列表
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      value: null,
      loading: false
    };
  },
  created() {
  },
  methods: {
    getDetail(id) {
      if (!id) return;
      const params = { id };
      this.loading = true;
      processManagementDetail(params).then(res => {
        this.loading = false;
        if (res.code === 200 && res.data) {
          if (typeof res.data === 'string') {
            res.data = this.jsonParse(res.data, []);
          }
          if (res.data[0]) this.$emit('handleQuote', res.data[0]);
        } else {
          ElMessage.error(res.message);
        }
      });
    },
    handleChange(id) {
      this.getDetail(id);
      this.$emit('handleChange');
    },
    jsonParse(str, defaultValue = undefined) {
      if (!str) return defaultValue;
      try {
        return JSON.parse(str);
      } catch (error) {
        return defaultValue;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.width240 {
  .el-select-dropdown__item {
    width: 240px !important;
  }
}
</style>
